package com.itcast.demo_one.kotlin

fun main() {
    // println(ifDemo(10, 20))
    // whenDemo1(1)
    // whenDemo2(10)

    forDemo()
}

fun ifDemo(num1: Int, num2: Int):  Int{
    // 写法1
    /*if (num1 > num2) {
        return num1
    } else {
        return num2
    }*/

    // 写法2
    /*return if (num1 > num2) {
        num1
    } else {
        num2
    }*/

    // 写法3
    return if (num1 > num2) num1 else num2

}


fun whenDemo1(num: Int) {
    when (num) {
        1 -> println("One")
        2 -> println("Two")
        3 -> println("Three")
        else -> println("Other")
    }
}

/**
 * 使用 when 语句, 根据成绩输出对应的等级
 */
fun whenDemo2(score: Int) {
    when (score) {
        in 90..100 -> println("A")
        in 80 until 90 -> println("B")
        in 70..79 -> println("C")
        in 60..69 -> println("D")
        else -> println("E")
    }
}


fun forDemo() {
    // [1, 10]
    /*for (i in 1..10) {
        println(i)
    }*/

    // [1, 10)
   /* for (i in 1 until 10) {
        println(i)
    }*/

    // 步长值
    /*for (i in 1..10 step 5) {
        println(i)
    }*/

    // 降序
    for (i in 10 downTo 1 step 2) {
        println(i)
    }
}